package com.hnx.admin.aurora.security.filter;

import com.hnx.admin.aurora.jwt.api.JwtFilter;
import com.hnx.admin.aurora.security.core.SecurityProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;

/*
创建人： 倔强的头发
创建时间：2025/6/14
功能描述:

*/
@Component
@RequiredArgsConstructor
public class JwtTokenFilter  extends OncePerRequestFilter {
    private final SecurityProperties securityProperties;
    private final JwtFilter jwtFilter;
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        if(Objects.nonNull(request)){
            String uri = request.getRequestURI();
            if(Arrays.stream(securityProperties.getOpenApi()).noneMatch(n->n.equalsIgnoreCase(uri))){
                jwtFilter.match(request);
            }
        }
        filterChain.doFilter(request,response);
    }
}
